# -*- coding: utf-8 -*-
#
# File: TrainingEventView.py
#
# Copyright (c) 2009 by ngi644.net
# Generator: ArchGenXML Version 2.4.1
#            http://plone.org/products/archgenxml
#
# GNU General Public License (GPL)
#

__author__ = """Takashi NAGAI <nagai@ngi644.net>"""
__docformat__ = 'plaintext'

##code-section module-header #fill in your manual code here
##/code-section module-header

from zope import interface
from zope import component
from Products.CMFPlone import utils
from Products.Five import BrowserView
from zope.interface import implements
from Products.tfcaEvent.interfaces.ITrainingEvent import ITrainingEvent
from Products.CMFDynamicViewFTI.browserdefault import BrowserDefaultMixin

from Acquisition import aq_inner
from Products.CMFCore.utils import getToolByName
from DateTime import DateTime
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.CMFPlone import PloneMessageFactory as _
from zope.component import getMultiAdapter

class TrainingEventView(BrowserView):
    """
    """
    implements(ITrainingEvent)

    ##code-section class-header_TrainingEventView #fill in your manual code here
    ##/code-section class-header_TrainingEventView

    def getApplyList(self, obj):
        
        if not self.isManager():
            return ''
        else:
            #import pdb;pdb.set_trace()
            cur_path = '/'.join(obj.getPhysicalPath())
            base_query = {}
            base_query['sort_on'] = 'created'
            base_query['path'] = {'query':cur_path, 'depth':1}
            portal_catalog = getToolByName(self, 'portal_catalog')
            return portal_catalog(base_query)


    def isAnon(self):
        portal_state = getMultiAdapter((self.context, self.request),
                                        name=u'plone_portal_state')
        return portal_state.anonymous()

    def isManager(self):
        portal_state = getMultiAdapter((self.context, self.request),
                                        name=u'plone_portal_state')
        return portal_state.member().has_role('Manager')



##code-section module-footer #fill in your manual code here
##/code-section module-footer


